﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using ParamSetCollection.General.ParamTable;
using ParamSetCollection.General.Parameters.Alarms;
using ParamSetCollection.General.Parameters.Normal;

namespace ParamSetCollection.General.ParamTable.JTRII.DataTable
{
    public class JTRMegmitAddrHelper: AddrHelper
    {

        public override void SortParams(ParamHelper tableData)
        {
            CommDataUnit.AddrHead = 13000;

            SortCTX(tableData.CtxParam);
            SortSV(tableData.SvParam);
            SortPV(tableData.PvParam);
            SortInput(tableData.InParam);
            SortOutput(tableData.OutParam);
            SortAlarm(tableData.alarmsHelper);

        }

        private static void SortCTX(ParamGroupUnit tg)
        {
            int addr = 13000;
            List<string> keys = tg.shortParamDic.Keys.ToList();
            for (int i = 0; i < keys.Count; i++)
            {
                tg.shortParamDic[keys[i]].Position = addr.ToString();
                addr++;
            }

            addr = 13023;
            keys = tg.dwParamDic.Keys.ToList();
            for (int i = 0; i < keys.Count; i++)
            {
                tg.dwParamDic[keys[i]].Position = addr.ToString();
                addr = addr + 2;

            }

        }
        private static void SortSV(ParamGroupUnit tg)
        {
            int addr = 13100;
            List<string> keys = tg.shortParamDic.Keys.ToList();
            for (int i = 0; i < keys.Count; i++)
            {
                if(keys[i]== "Zone1UpperTempOffsetSV")
                {
                    addr = 13160;
                }
                else if(keys[i]== "Zone1UpperPValueSV")
                {
                    addr = 13220;
                }
                else if (keys[i] == "FanInvertor1FreqSV")
                {
                    addr = 13330;
                }
                else if (keys[i] == "PCBCountMaxAlertSV")
                {
                    addr = 13365;
                }
                else if (keys[i] == "NitroPreheatTempOffsetSV")
                {
                    addr = 13399;
                }

                tg.shortParamDic[keys[i]].Position = addr.ToString();
                addr++;
            }


            addr = 13550;
            keys = tg.dwParamDic.Keys.ToList();
            for (int i = 0; i < keys.Count; i++)
            {
                tg.dwParamDic[keys[i]].Position = addr.ToString();
                addr = addr + 2;

            }




        }
        private static void SortPV(ParamGroupUnit tg)
        {
            int addr = 15050;
            List<string> keys = tg.shortParamDic.Keys.ToList();
            for (int i = 0; i < keys.Count; i++)
            {
                if (keys[i] == "Fan1InvertorFreqPV")
                {
                    addr = 15110;
                }
                else if (keys[i] == "Zone1UpperTempPV")
                {
                    addr = 15200;
                }
                else if (keys[i] == "Zone1UpperSwtState")
                {
                    addr = 15350;
                }
                else if (keys[i] == "Zone1UpperCurrent")
                {
                    addr = 15400;
                }
                else if (keys[i] == "Zone1UpperPValueSV")
                {
                    addr = 15440;
                }
                else if (keys[i] == "Zone1UpperMV")
                {
                    addr = 15540;
                }
                else if (keys[i] == "Zone1UpperAutoTuningState")
                {
                    addr = 15580;
                }
                else if (keys[i] == "Zone1UpperAutoTuningState")
                {
                    addr = 15580;
                }
                else if (keys[i] == "UpperFan1SpeedPV")
                {
                    addr = 15850;
                }
                else if (keys[i] == "UpperFan1StatePV")
                {
                    addr = 15900;
                }
                else if (keys[i] == "UpperFan1StatePV")
                {
                    addr = 15900;
                }

                tg.shortParamDic[keys[i]].Position = addr.ToString();
                addr++;
            }


            addr = 15000;
            keys = tg.dwParamDic.Keys.ToList();
            for (int i = 0; i < keys.Count; i++)
            {
                if (keys[i] == "Rail1PCBPos1")
                {
                    addr = 15640;
                }

                tg.dwParamDic[keys[i]].Position = addr.ToString();
                addr = addr + 2;

            }
        }
        private static void SortInput(ParamGroupUnit tg)
        {

        }
        private static void SortOutput(ParamGroupUnit tg)
        {

        }
        private static void SortAlarm(AlarmsHelper ah)
        {
            //使能地址设置待整理，暂定0，动作地址待定
            ah.SetAddr(0,17015,0);

        }


    }
}
